class code2 {
    //括号匹配
    //右括号不可能在st中
    public boolean isValid(String s) {
        Stack<Character> st = new Stack<>();
        HashMap<Character,Character> map = new HashMap<>();
        map.put('}','{');
        map.put(']','[');
        map.put(')','(');
        char[] ss = s.toCharArray();
        for(char ch:ss) {
            if(ch=='{'||ch=='['||ch=='(') {
                st.push(ch);
            } else {
                if(st.isEmpty() || st.pop()!=map.get(ch)) {
                    return false;
                }
            }
        }

        return st.isEmpty();
    }
}